import * as ActionTypes from './ActionTypes.js';
import axios from 'axios';

let _id = 0;
// [] 运算符
const obj = {
    "0":'未完成',
    "1":'已完成',
    "2":'进行中'
}
// obj[name];
function cfgFn(){
    return {
        name:'小红',
        age:'32'
    }
}
const Data = {
    async getApi(ajaxCfg){
        let data = await axios.get(ajaxCfg.url,{params:ajaxCfg.cfg},
        {
            headers: ajaxCfg.headers
        })
        return data;
    }
}
export const AddTodo = (text,viewData,ajaxCfg,dispatch)=>{
    return{
        type:ActionTypes.ADD_TODO,
        text:text,
        id:_id ++,
        cfgFn:cfgFn(),
        viewData:viewData,
        getApi:Data.getApi(ajaxCfg).then((res)=>{
            dispatch({
                type:ActionTypes.EDIT_TODO,
                id:_id-1,
                data:res.data
            });
        })
        // name:obj[name]
    }
}
export const Search = (text,value,searchCfg)=>{
    // searchCfg:{
    //     val:'', //搜索输入名字
    //     stateDate:'', //开始日期
    //     endDate:'', //结束日期
    // }
    return {
        type:ActionTypes.SEARCH_BUTTON,
        text:text,
        value:value,
        searchCfg:searchCfg
    }
}
// export const EditTodo = (text)=>{
//     return {
//         type:ActionTypes.EDIT_TODO,
//         text:text
//     }
// }
export const RemoveTodo = (id)=>{
    return {
        type:ActionTypes.REMOVE_TODO,
        id:id
    }
}
